﻿using WcfGeebaServer.Users;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using System.Collections.Generic;
using WcfGeebaServer.ContentManage;

namespace TestGeeba
{
    
    
    /// <summary>
    ///This is a test class for MemberTest and is intended
    ///to contain all MemberTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MemberTest
    {

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Member Constructor
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        //[HostType("ASP.NET")]
        //[AspNetDevelopmentServerHost("C:\\Users\\ALEX\\Documents\\Visual Studio 2010\\Projects\\LAST_VERSION\\WcfService1", "/")]
        //[UrlToTest("http://localhost:18808/")]
        public void MemberConstructorTest()
        {
            Member target = new Member("testUsername", "123456", true);
            //Assert.Inconclusive("New member was created.");
        }


        /// <summary>
        ///A test for IsActive
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        //[HostType("ASP.NET")]
        //[AspNetDevelopmentServerHost("C:\\Users\\ALEX\\Documents\\Visual Studio 2010\\Projects\\LAST_VERSION\\WcfService1", "/")]
        //[UrlToTest("http://localhost:18808/")]
        public void IsActiveTest()
        {
            Member target = new Member("testUsername", "123456", true);
            WcfGeebaServer.ContentManage.GForum.GetForum().register("testUsername", "123456");
            bool expected = true;
            bool actual = target.IsActive;
            Assert.AreEqual(expected, actual);

            expected = false;
            target.setIsActive(false);
            actual = target.IsActive;
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        [TestMethod()]
        public void isLawBreakerTest()
        {
            Member target = new Member("testUsername1", "123456", true);
            GForum.GetForum().register("testUsername1", "123456");
            GForum.GetForum().addSubForum("subforum", target);
            GSubForum sf = GForum.GetForum().getSubForum("subforum");
            sf.publish(new GThread("subj", "content", target));
            Assert.IsFalse(target.isLawBreaker());
            target.setIsActive(false);
            sf.publish(new GThread("subj", "content", target));
            Assert.IsTrue(target.isLawBreaker());
        }

        [TestMethod()]
        public void BanMemberTest()
        {
            Member target = new Member("testUsername2", "123456", true);
            GForum.GetForum().register("testUsername2", "123456");
            target.BanMember();
            User user = GForum.GetForum().entry();
            Assert.IsNull(GForum.GetForum().login(user, target.Username, "123456"));

        }

    }
}
